import { Router, Request, Response, NextFunction } from 'express';
import {
    followUser,
    unfollowUser,
    getFollowers,
    getFollowing,
    getFriends,
} from '../controllers/socialRelationController';
import { authenticate } from '../middleware/auth';

const router = Router();

// 关注用户
router.post('/follow', authenticate, async (req: Request, res: Response, next: NextFunction) => {
    try {
        await followUser(req, res);
    } catch (error) {
        next(error);
    }
});

// 取消关注
router.delete('/follow/:targetId', authenticate, async (req: Request, res: Response, next: NextFunction) => {
    try {
        await unfollowUser(req, res);
    } catch (error) {
        next(error);
    }
});

// 获取关注者列表
router.get('/followers/:userId', async (req: Request, res: Response, next: NextFunction) => {
    try {
        await getFollowers(req, res);
    } catch (error) {
        next(error);
    }
});

// 获取关注列表
router.get('/following/:userId', async (req: Request, res: Response, next: NextFunction) => {
    try {
        await getFollowing(req, res);
    } catch (error) {
        next(error);
    }
});

// 获取好友列表
router.get('/friends', authenticate, async (req: Request, res: Response, next: NextFunction) => {
    try {
        await getFriends(req, res);
    } catch (error) {
        next(error);
    }
});

export default router; 